#ifndef __command_H__
#define __command_H__

#include "processPool.h"
#define ERROR_CHECK_M(retVal, val, msg, answer_client)\
{\
    if (val == retVal) {\
        sprintf(answer_client, "%s,%s", msg, " No such file or directory");\
        return;\
    }\
}

//检查错误，为了不终止子进程
#define ERROR_CHECK_G(retVal, val, msg)\
{\
    if (val == retVal) {\
        fprintf(stderr, "%s error", msg);\
        return -1;\
    }\
}
typedef struct command_t {
    char com[20];
    char name[100];
}command_t;

typedef  struct {
    int len;
    char buff[BUFFERSIZE];
}train_t1;


int do_command(char* command, char* answer_client, int fd);
int prase(char* command, command_t* pcom);
int search(char* com);
void execute(command_t* pcom, char* answer_client, int fd);

//命令
void cd(char* name, char* answer_client);
void pwd(char* answer_client);
void cmd_ls(char* answer_client);
char *trans_file_access_form(void* file_stat);
void rm(char* name, char* answer_client);
void mkdir_my(char* name, char* answer_client);

//传输文件
off_t statSize(int fileFd);  //获取文件长度
int sendn(int fd, const void* str, int len);
int recvn(int fd, const void* str, int len);

//下传传输文件
int transferFile(int peerfd,const char *filename);
int choiceHow(int peerfd,const char *filename);
int isInserver(const char *filename);
int sendFile(int peerfd,const char* filename);

//接收文件函数
int choiceFile(int peerfd, const char* filename);
int recv_file(int fd);  //客户端会把文件名通过网络socket通信小火车传过来，这里就不用文件名参数了
int recv_interrupt_file(const char* filename, int peerfd);  //断点续传


#endif
